//package com.sse.product.handler;
//
//import com.sse.product.common.ResultCode;
//import com.sse.product.exception.BizRuntimeException;
//import com.sse.product.model.rbac.ResponseVo;
//import lombok.SneakyThrows;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.MediaType;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.security.access.AccessDeniedException;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
//import static com.sse.product.common.Constants.jacksonMapper;
//
//@RestControllerAdvice
//public class ProductGlobalExceptionHandler implements ResponseBodyAdvice {
//
//    @Override
//    public boolean supports(MethodParameter returnType, Class converterType) {
//        return true;
//    }
//
//    @SneakyThrows
//    @Override
//    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
//        if(body instanceof String) {
//            return ResponseVo.assemble(ResultCode.SYSTEM_ERROR,jacksonMapper.writeValueAsString(body));
//        }
//        if(body instanceof ResponseVo)
//            return body;
//        return body;
//    }
//
//    @ExceptionHandler(RuntimeException.class)
//    public ResponseVo runTimeErrorHandler(RuntimeException e) {
//        return ResponseVo.assemble(ResultCode.SYSTEM_ERROR,e.getMessage());
//    }
//
//    @ExceptionHandler(AccessDeniedException.class)
//    public ResponseVo accessDeniedErrorHandler(AccessDeniedException e) {
//        return ResponseVo.assemble(ResultCode.ACCESS_DENY,e.getMessage());
//    }
//
//}
